#!/usr/bin/env node

import { program } from 'commander'
import pkg from './package.json' with { type: 'json' };
import getLanguage from './utils/getLanguage'
import create from './action/create'

const lang = getLanguage()

program
   .name('wang')
   .description(pkg.description)
   .version(pkg.version, '-v, --version', lang.version)
   .usage('<command> [options]')

program
  .option('-N, --name <project-name>', lang.create.options.projectName)
  .option('-T, --template <template-name>', lang.create.options.template)
  
program
.command('create')
.description(lang.create.description)
.action(() => {
  const args = program.opts()
  create(args)
})
    
program.parse(process.argv);

// 错误静默
process.on('uncaughtException', (error) => {
    if (error instanceof Error && error.name === 'ExitPromptError') {
      console.log('👋 until next time!');
    } else {
      // Rethrow unknown errors
      throw error;
    }
  });